let mla = []
let mls = [false, false, false]
let mli = []
const ml = ['rain', 'sea', 'fire']

function music() {
    for (let i = 0; i < 3; i++) {
        mla.push(new Audio())
        mla[i].src = 'audios/' + ml[i] + '.mp3'
        mla[i].loop = true
        mls.push(false)
        mli.push(document.getElementById(ml[i]))
    }
}

function stopAll() {
    for (let i = 0; i < 3; i++) {
        mla[i].pause()
        mli[i].src = 'imgs/' + ml[i] + 'stop.svg'
        mls[i] = false
    }
}

function play(x) {
    const ts = mls[x]
    stopAll()
    mls[x] = ts
    if (!mls[x]) mli[x].src = 'imgs/' + ml[x] + '.svg'
    mls[x] = !mls[x]

    if (mls[x]) {
        mla[x].play()
    }
}